const Service = require("egg").Service;
const { Configuration, OpenAIApi } = require("openai");
const { execScript } = require("../utils/index.js");


const configuration = new Configuration({
  apiKey: 'YOU KEY',
});
const openai = new OpenAIApi(configuration);

class gptAiService extends Service {
 
  async sendTalk(text) {
    console.log('sendTalk:',text);
    const completion = await openai.createCompletion({
      model: "text-davinci-003",
      prompt: text,
    });
    console.log(completion.data.choices[0].text);
    return completion.data.choices[0].text;
  }
}
module.exports = gptAiService;
